// import { createStore } from 'vuex';
import Vue from 'vue'
import Vuex from 'vuex'
// import { designData } from 'ts-design/packages/store';
// import { tsElementStore } from 'ts-element/packages/utils/store'; // 加载store
Vue.use(Vuex)
const modulesFiles = require.context('./modules', true, /\.js$/);
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
    const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1');
    modules[moduleName] = modulesFiles(modulePath).default;
    return modules;
}, {});

// export default createStore({
//     state: {},
//     mutations: {},
//     actions: {},
//     modules: {...modules },
// });

export default new Vuex.Store({
    state: {
        // ...designData.state,
        // ...tsElementStore.state,
        commonData: {
            // parent: 1
        },
        theme: '#1b79fb'// 主题色
    },
    mutations: {
        // ...designData.mutations,
        setTheme(state, newData) {
            document.getElementById(process.env.VUE_APP_CONTAINER).style.setProperty('--theme-color', newData)
            document.getElementById(process.env.VUE_APP_CONTAINER).style.setProperty('--theme-bg', newData + 'bf')
            state.theme = newData
        },
        // ...tsElementStore.mutations,
        setCommonData(state, val) {
            state.commonData = val;
        },
        // 弹窗关闭设置
        setDialog(state, v) {
            if (typeof v === 'function') {
                state.closeDialog = v
            }
        },
        setData(state, { label, value }) {
            state[label] = value;
        },
    },
    actions: {
        // ...designData.actions,
        // ...tsElementStore.actions,
    },
    getters: {
        // ...designData.getters,
        // ...tsElementStore.actions,
    },
    modules: { ...modules }
})
